<?php

class UserManager{

    static function adminSignedIn(sfEvent $event)
	{
		if($event->getSubject()->getUser()->getParameter() == 'product manager'){
			$event->getSubject()->redirect('productManagement/index');
		}
    }

	static function productManagerRestricter(sfEvent $event)
	{
		# if current user IS Product Manager restrict his movements in CMS
		if(sfContext::getInstance()->getUser() && sfContext::getInstance()->getUser()->isAuthenticated()
				&& !sfContext::getInstance()->getUser()->hasCredential('admin')){
			$ar = $event->getParameters();

			if($ar['module'] != 'productManagement' && $ar['module'] != 'product'){
				$event->getSubject()->redirect('productManagement/index');
			}
		}
	}


	static function productManagerProductRightsChecker(sfEvent $event){
		$params = $event->getParameters();

		if($params['product'] &&
				sfContext::getInstance()->getUser() &&
				sfContext::getInstance()->getUser()->isAuthenticated() &&
				!sfContext::getInstance()->getUser()->hasCredential('admin') &&
				sfContext::getInstance()->getUser()->getGuardUser() &&
				$params['product']['created_by'] != sfContext::getInstance()->getUser()->getGuardUser()->getId()){

		 echo 'your can not change this product information';
		 exit;
		}

				
		
	}
}